package com.cn.file;

import java.io.Serializable;

/**
 * 消息存储后返回结果
 */
public class AppendMessageResult implements Serializable {
    // 存储结果
    private AppendMessageStatus status;
    // 本消息写入的起始位置
    private long wroteOffset;
    // 本消息的长度
    private int wroteBytes;
    // 消息主键
    private String msgId;
    // 存储时间
    private long storeTimestamp;
    // Consume queue's offset(step by one)
    private long logicsOffset;
    private long pagecacheRT = 0;
    private int opaque;

    private int msgNum = 1;

    public AppendMessageResult(AppendMessageStatus status) {
        this(status, 0, 0, "", 0, 0, 0, 0);
    }

    public AppendMessageResult(AppendMessageStatus status, long wroteOffset, int msgLength, String msgId,
                               long storeTimestamp, long logicsOffset, long pagecacheRT, int opaque) {
        this.status = status;
        this.wroteOffset = wroteOffset;
        this.wroteBytes = msgLength;
        this.msgId = msgId;
        this.storeTimestamp = storeTimestamp;
        this.logicsOffset = logicsOffset;
        this.pagecacheRT = pagecacheRT;
        this.opaque = opaque;
    }

    public long getPagecacheRT() {
        return pagecacheRT;
    }

    public void setPagecacheRT(final long pagecacheRT) {
        this.pagecacheRT = pagecacheRT;
    }

    public boolean isOk() {
        return this.status == AppendMessageStatus.PUT_OK;
    }

    public AppendMessageStatus getStatus() {
        return status;
    }

    public void setStatus(AppendMessageStatus status) {
        this.status = status;
    }

    public long getWroteOffset() {
        return wroteOffset;
    }

    public void setWroteOffset(long wroteOffset) {
        this.wroteOffset = wroteOffset;
    }

    public int getWroteBytes() {
        return wroteBytes;
    }

    public void setWroteBytes(int wroteBytes) {
        this.wroteBytes = wroteBytes;
    }

    public String getMsgId() {
        return msgId;
    }

    public void setMsgId(String msgId) {
        this.msgId = msgId;
    }

    public long getStoreTimestamp() {
        return storeTimestamp;
    }

    public void setStoreTimestamp(long storeTimestamp) {
        this.storeTimestamp = storeTimestamp;
    }

    public long getLogicsOffset() {
        return logicsOffset;
    }

    public void setLogicsOffset(long logicsOffset) {
        this.logicsOffset = logicsOffset;
    }

    public int getMsgNum() {
        return msgNum;
    }

    public void setMsgNum(int msgNum) {
        this.msgNum = msgNum;
    }

    public int getOpaque() {
        return opaque;
    }

    public void setOpaque(int opaque) {
        this.opaque = opaque;
    }

    @Override
    public String toString() {
        return "AppendMessageResult{" +
                "status=" + status +
                ", wroteOffset=" + wroteOffset +
                ", wroteBytes=" + wroteBytes +
                ", msgId='" + msgId + '\'' +
                ", storeTimestamp=" + storeTimestamp +
                ", logicsOffset=" + logicsOffset +
                ", pagecacheRT=" + pagecacheRT +
                ", msgNum=" + msgNum +
                ", opaque=" + opaque +
                '}';
    }

}
